import http from '@/api'
import { PORT1 } from '@/api/config/port'
import { Entity, EnumsReq, EnumsRes, SmsRes, Violation } from '@/api/interface/index'

// 全局字典
export const Enums = (params: EnumsReq) => {
  return http.get<EnumsRes[]>(PORT1 + `/api/common/enums`, params, {
    cancel: false,
  })
}

// entity 字典
export const EntityEnums = (params: { emirate: string }) => {
  return http.get<Entity[]>(PORT1 + `/api/entity/search`, params, {
    loading: true,
    cancel: false,
  })
}

// other entity 字典
export const OtherEntityEnums = () => {
  return http.get<string[]>(
    PORT1 + `/api/violation/suggestion`,
    {},
    {
      loading: true,
      cancel: false,
    }
  )
}

// website上传文件
export const UploadFile = (params: any) => {
  return http.post<string>(PORT1 + `/api/file/upload`, params, { loading: true, cancel: false })
}

// 创建 Violation
export const CreateViolation = (params: Partial<Violation>) => {
  return http.post(PORT1 + `/api/violation/create`, params, { loading: true })
}

// 发送短信
export const SendSms = (params: { mobile: string; fullName: string; email: string }) => {
  return http.post<SmsRes>(PORT1 + `/api/otp/create`, params, { loading: true })
}

// 校验短信
export const CheckSms = (params: { mobile: string; code: string }) => {
  return http.post<{ success: boolean; token: string }>(PORT1 + `/api/otp/check`, params, {
    loading: true,
  })
}
